package cn.neusoft.query;

import cn.neusoft.pojo.Menu;
import cn.neusoft.pojo.Permission;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class PermissionQuery extends BaseQuery{

    private Long roleId;

    /**
     * permission表联查role_permission表 根据role_id查询对应的权限
     * @return
     */
    public Wrapper getJoinWrapper() {

        MPJLambdaWrapper<Menu> wrapper = new MPJLambdaWrapper<>();
        wrapper.setAlias("p")
                .selectAll(Permission.class)
                .leftJoin(" role_permission rp on p.id=rp.permission_id ");
        if (roleId!=null && roleId!=0){
            wrapper.eq("rp.role_id",roleId);
        }

        return wrapper;
    }

}
